package es.us.lsi.daw.soportePropiedades;

import java.beans.PropertyEditorSupport;

import org.slf4j.LoggerFactory;

import es.us.lsi.daw.model.security.enums.GroupEnum;

public class GroupEnumEditor extends PropertyEditorSupport {

	@Override
	public void setAsText(String text) throws IllegalArgumentException {

		if (text!= null  && !text.isEmpty()) {
			GroupEnum valor = null;
			try{
				valor= GroupEnum.getFromString(text);
			}catch (Exception e) {
				LoggerFactory.getLogger(this.getClass()).error("Unknown GroupEnum: " + text);
			}
			setValue(valor );
		} else {
			setValue(null);
		}
	}
	
	
	@Override
	public String getAsText() {
		if(this.getValue() != null)
			return this.getValue().toString();
		return super.getAsText();
	}
}
